package com.hh.system.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.hh.baseframework.exception.MessageException;
import com.hh.system.bean.HhXtData;
import com.hh.system.service.impl.HhXtDataService;
import com.hh.system.util.StaticVar;
import com.hh.system.util.base.BaseAction;
import com.hh.system.util.model.ReturnModel;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public class ActionData extends BaseAction implements ModelDriven<HhXtData> {
	private HhXtData hhXtData = new HhXtData();

	@Autowired
	private HhXtDataService hhXtDataService;

	public void queryDataTreeByTypeAndPid() {
		List<HhXtData> hhXtDatas = hhXtDataService.queryMenuListByPid(
				hhXtData.getNode(), hhXtData.getType());
		this.returnResult(hhXtDatas);
	}

	public void queryAllDataTreeByTypeAndPid() {
		List<HhXtData> hhXtDatas = hhXtDataService
				.queryAllMenuListByPid(hhXtData.getType());
		this.returnResult(hhXtDatas);
	}

	public void findObjectById() {
		HhXtData hhXtData = hhXtDataService.findObjectById(this.hhXtData
				.getId());
		this.returnResult(hhXtData);
	}

	public void save() {
		try {
			HhXtData hhXtData = hhXtDataService.save(this.hhXtData);
			this.getResultMap().put("object", hhXtData);
		} catch (MessageException e) {
			this.getResultMap().put("returnModel",
					new ReturnModel(e.getMessage()));
		}
		this.returnResult();
	}

	public void deleteByIds() {
		hhXtDataService.deleteByIds(this.getIds());
	}

	public HhXtData getModel() {
		return hhXtData;
	}

	public String test() {
		return StaticVar.JSP;
	}
}
